package com.kanshu.ksgb.fastread.doudou.module.personal.fragment

import android.os.Bundle
import com.kanshu.ksgb.fastread.doudou.app.constants.Constants
import com.kanshu.ksgb.fastread.doudou.base.baseui.BaseListFragment
import com.kanshu.ksgb.fastread.doudou.common.net.bean.BaseResult
import com.kanshu.ksgb.fastread.doudou.common.net.bean.PageRequestParams
import com.kanshu.ksgb.fastread.doudou.common.net.retrofit.RetrofitHelper
import com.kanshu.ksgb.fastread.doudou.common.net.rx.BaseObserver
import com.kanshu.ksgb.fastread.doudou.common.util.StorageUtils
import com.kanshu.ksgb.fastread.doudou.common.business.event.RedPointEvent
import com.kanshu.ksgb.fastread.doudou.module.personal.activity.MyFeedbackAdapter
import com.kanshu.ksgb.fastread.doudou.module.personal.bean.FeedbackBean
import com.kanshu.ksgb.fastread.doudou.module.personal.presenter.PersonCenterService
import com.kanshu.ksgb.fastread.doudou.common.business.utils.UserUtils
import io.reactivex.disposables.Disposable
import org.greenrobot.eventbus.EventBus


/**
 * Title:
 * Description:
 * Copyright: Copyright(c)2018
 * Company: 看书网
 * CreateTime: 2018/4/19 17:23
 *
 * @author EvanHe
 * @version 1.0
 */
class FeedbackListFragment : BaseListFragment<FeedbackBean>() {

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        getContentAysnc(PageRequestParams())
    }

    override fun provideAdapter(): MyFeedbackAdapter {
        return MyFeedbackAdapter(activity!!, mList)
    }

    override fun getContentAysnc(params: PageRequestParams?) {
        val helper = RetrofitHelper.getInstance()
        helper.createService(PersonCenterService::class.java).feedbackList()
                .compose(asyncRequest())
               .subscribe(object : BaseObserver<List<FeedbackBean>>() {

                    override fun onResponse(tBaseResult: BaseResult<List<FeedbackBean>>?, t: List<FeedbackBean>?, disposable: Disposable?) {
                        showContent(tBaseResult)
                        StorageUtils.setPreference(activity!!, Constants.SP_NAME, "is_read_feedback_" + UserUtils.getUserId(), false)
                        EventBus.getDefault().post(RedPointEvent())
                    }
                })
    }

}